package com.canyou.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 基础配置参数
 *
 * @author cgz
 * @date 2019-01-10
 */
@Data
@Component
@ConditionalOnClass(WxMaService.class)
@ConfigurationProperties(prefix = "cys.wxapp")
public class WxMiniAppConfig {

    /**
     * 小程序APP_ID
     */
    private String appId;
    /**
     * 小程序APP_Secret
     */
    private String secret;

    @Bean
    public WxMaService initWxMaService() {
        WxMaService wxMaService = new WxMaServiceImpl();
        WxMaInMemoryConfig wxMaConfig = new WxMaInMemoryConfig();
        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(secret);
        wxMaService.setWxMaConfig(wxMaConfig);
        return wxMaService;
    }
}
